<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 响应状态码是 2xx ----- 表示成功
    // 响应状态码是 3xx、4xx、5xx ---- 表示失败

    const xhr = new XMLHttpRequest()

    xhr.addEventListener('load',function(){
        // 通过 xhr.status 获取响应状态码
        // console.log(xhr.status)
        if(xhr,status >= 200 && xhr.status < 300){
            console.log('成功',JSON.parse(xhr.response))
        }else if (xhr.status >= 300){
            console.log('失败',JSON.parse(xhr.response));
        }
    })
    
    xhr.open('POST', 'http://www.itcbc.com:3006/api/addbook')
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
    xhr.send('bookna=aa&author=bbb&publisher=ccc')
    </script>
</body>
</html>